package cn.qiao.benchmark;

import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnection;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

/**
 * desc:
 *
 * @author qiao
 * @date 2024年02月05日 21:19
 */
public class LettuceServiceImpl implements RedisService {

    private RedisConnectionFactory redisConnectionFactory;


    @Override
    public void set(String key, String value) {
        RedisConnection connection = redisConnectionFactory.getConnection();
        connection.set(key.getBytes(),value.getBytes());

    }

    @Override
    public String get(String key) {
        RedisConnection connection = redisConnectionFactory.getConnection();
        byte[] bytes = connection.get(key.getBytes());
        if (bytes == null){
            return null;
        }
        return new String(bytes);
    }

    public void pipelined(String key) {
        RedisConnection connection = redisConnectionFactory.getConnection();
        connection.openPipeline();
        connection.closePipeline();
        connection.isPipelined();
    }

    public LettuceServiceImpl(RedisConnectionFactory redisConnectionFactory) {
        this.redisConnectionFactory = redisConnectionFactory;
    }
}
